/**
 * Created by Administrator on 2018/3/21 0021.
 */
const mongoose = require('mongoose')
const config = require('../config')

mongoose.connect(config.db, {}, (err) => {
  if (err) {

  }
  console.log('链接成功')
})
const { Schema } = mongoose
const PageSchema = new Schema({
  title: { type: String },
  path: { type: String },
  imgUrl: { type: String },
  content: { type: String },
  author: { type: String },
  is_vaild: { type: Boolean, default: true },
  read_count: { type: Number, default: 0 },
  create_at: { type: Date, default: Date.now },
  update_at: { type: Date, default: Date.now },
})
PageSchema.pre('save', function (next) {
  this.update_at = new Date()
  next()
})
const Page = mongoose.model('Page', PageSchema)
const page = new Page({
  title: '哈哈哈',
  path: 'about',
  content: 'dfjlsdjfklsddsfklsdflsd sdfjsdklfsd',
})
page.save((err, page) => {
  if (err) {
    console.log(err)
  }
  console.log('插入成功', page)
})
